package com.cdut.hwadeefsc.service.impl;

import com.cdut.hwadeefsc.entity.activities;
import com.cdut.hwadeefsc.mapper.activitiesMapper;
import com.cdut.hwadeefsc.service.activitiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class activitiesServiceImpl implements activitiesService { // 类名首字母大写

    @Autowired
    private activitiesMapper activitiesMapper;

    @Override
    public List<activities> getActivitiesByClassId(Long classId) { // 参数类型改为Long
        return activitiesMapper.findByClassId(classId);
    }

    @Override
    public List<activities> getAllActivities() {
        return activitiesMapper.findAll();
    }

    @Override
    public List<activities> getActivitiesByStudentId(Long studentId) { // 参数类型改为Long
        return activitiesMapper.findByStudentId(studentId);
    }

    @Override
    public activities getActivityById(Long id) { // 参数类型改为Long
        return activitiesMapper.findById(id);
    }

    @Override
    public boolean addActivity(activities activity) {
        // 自动设置创建时间和更新时间
        Date now = new Date();
        activity.setCreatedAt(now);
        activity.setUpdatedAt(now);
        return activitiesMapper.insert(activity) > 0;
    }

    @Override
    public boolean updateActivity(activities activity) {
        // 自动更新修改时间
        activity.setUpdatedAt(new Date());
        return activitiesMapper.update(activity) > 0;
    }

    @Override
    public boolean deleteActivity(Long id) { // 参数类型改为Long
        return activitiesMapper.delete(id) > 0;
    }

    @Override
    public List<activities> getActivitiesByStatus(String status) {
        return activitiesMapper.findByStatus(status);
    }
}




